import group from "./group.json"
import field from "./field.json"
import type {MockMethod} from "vite-plugin-mock";
import success from "../success.json"
import enumslist from "./enum.json"
import {findDetailFromList, findItemById} from "../utils";


const groups = [
    {
        url: "/enum/group/list",
        method: "get",
        response: ({body, query}: any) => {
            return group;
        }
    },
    {
        url: "/enum/group/detail",
        method: "get",
        response: ({query}: any) => {
            return findDetailFromList(group.data, query.id, "enumGroupId");
        }
    },
    {
        url: "/enum/group/save",
        method: "post",
        response: () => {
            return success;
        }
    },
    {
        url: "/enum/group/delete",
        method: "delete",
        response: () => {
            return success;
        }
    }
]

const fields = [
    {
        url: "/enum/field/list",
        method: "post",
        response: ({body, query}: any) => {
            return field;
        }
    },
    {
        url: "/enum/field/detail",
        method: "get",
        response: ({query}: any) => {
            return findDetailFromList(field.data.list, query.id, "fieldId");
        }
    },
    {
        url: "/enum/field/save",
        method: "post",
        response: () => {
            return success;
        }
    },
    {
        url: "/enum/field/delete/:id",
        method: "delete",
        response: () => {
            return success;
        }
    }
]

const enums = [
    {
        url: "/enum/list",
        method: "get",
        response: ({body, query}: any) => {
            return enumslist;
        }
    },
    {
        url: "/enum/detail",
        method: "get",
        response: ({query}: any) => {
            return findDetailFromList(enumslist.data, query.enumId, "enumId");
        }
    },
    {
        url: "/enum/save",
        method: "post",
        response: () => {
            return success;
        }
    },
    {
        url: "/enum/delete/:id",
        method: "delete",
        response: () => {
            return success;
        }
    }
]

export default [...groups, ...fields, ...enums] as MockMethod[];
